<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>解密一个 S/MIME 加密的消息</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="function.openssl-pkcs12-read.html">« openssl_pkcs12_read</a></li>
      <li style="float: right;"><a href="function.openssl-pkcs7-encrypt.html">openssl_pkcs7_encrypt »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="ref.openssl.html">OpenSSL 函数</a></li>
    <li>解密一个 S/MIME 加密的消息</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="function.openssl-pkcs7-decrypt" class="refentry">
 <div class="refnamediv">
  <h1 class="refname">openssl_pkcs7_decrypt</h1>
  <p class="verinfo">(PHP 4 &gt;= 4.0.6, PHP 5, PHP 7, PHP 8)</p><p class="refpurpose"><span class="refname">openssl_pkcs7_decrypt</span> &mdash; <span class="dc-title">解密一个 S/MIME 加密的消息</span></p>

 </div>
 
 <div class="refsect1 description" id="refsect1-function.openssl-pkcs7-decrypt-description">
  <h3 class="title">说明</h3>
  <div class="methodsynopsis dc-description">
   <span class="methodname"><strong>openssl_pkcs7_decrypt</strong></span>(<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$infilename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type">string</span> <code class="parameter">$outfilename</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$recipcert</code></span>,<br>&nbsp;&nbsp;&nbsp;&nbsp;<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$recipkey</code><span class="initializer"> = ?</span></span><br>): <span class="type">bool</span></div>

  <p class="para rdfs-comment">
   使用由 <code class="parameter">recipcert</code> 和 <code class="parameter">recipkey</code> 指定的证书和与之关联的私钥解密 <code class="parameter">infilename</code> 文件中包含的 S/MIME 加密消息
  </p>
 </div>


 <div class="refsect1 parameters" id="refsect1-function.openssl-pkcs7-decrypt-parameters">
  <h3 class="title">参数</h3>
  <p class="para">
   <dl>
    
     <dt>
<code class="parameter">infilename</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">outfilename</code></dt>

     <dd>

      <p class="para">
       解密的消息将被存入的文件中，以<code class="parameter">outfilename</code>命名。
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">recipcert</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
    
     <dt>
<code class="parameter">recipkey</code></dt>

     <dd>

      <p class="para">
      </p>
     </dd>

    
   </dl>

  </p>
 </div>


 <div class="refsect1 returnvalues" id="refsect1-function.openssl-pkcs7-decrypt-returnvalues">
  <h3 class="title">返回值</h3>
  <p class="para">
   成功时返回 <strong><code>true</code></strong>， 或者在失败时返回 <strong><code>false</code></strong>。
  </p>
 </div>


 <div class="refsect1 examples" id="refsect1-function.openssl-pkcs7-decrypt-examples">
  <h3 class="title">范例</h3>
  <p class="para">
   <div class="example" id="example-945">
    <p><strong>示例 #1 <span class="function"><strong>openssl_pkcs7_decrypt()</strong></span> 范例</strong></p>
    <div class="example-contents">
<div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br /></span><span style="color: #FF8000">//&nbsp;$cert&nbsp;and&nbsp;$key&nbsp;are&nbsp;assumed&nbsp;to&nbsp;contain&nbsp;your&nbsp;personal&nbsp;certificate&nbsp;and&nbsp;private<br />//&nbsp;key&nbsp;pair,&nbsp;and&nbsp;that&nbsp;you&nbsp;are&nbsp;the&nbsp;recipient&nbsp;of&nbsp;an&nbsp;S/MIME&nbsp;message<br /></span><span style="color: #0000BB">$infilename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"encrypted.msg"</span><span style="color: #007700">;&nbsp;&nbsp;</span><span style="color: #FF8000">//&nbsp;this&nbsp;file&nbsp;holds&nbsp;your&nbsp;encrypted&nbsp;message<br /></span><span style="color: #0000BB">$outfilename&nbsp;</span><span style="color: #007700">=&nbsp;</span><span style="color: #DD0000">"decrypted.msg"</span><span style="color: #007700">;&nbsp;</span><span style="color: #FF8000">//&nbsp;make&nbsp;sure&nbsp;you&nbsp;can&nbsp;write&nbsp;to&nbsp;this&nbsp;file<br /><br /></span><span style="color: #007700">if&nbsp;(</span><span style="color: #0000BB">openssl_pkcs7_decrypt</span><span style="color: #007700">(</span><span style="color: #0000BB">$infilename</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$outfilename</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$cert</span><span style="color: #007700">,&nbsp;</span><span style="color: #0000BB">$key</span><span style="color: #007700">))&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"decrypted!"</span><span style="color: #007700">;<br />}&nbsp;else&nbsp;{<br />&nbsp;&nbsp;&nbsp;&nbsp;echo&nbsp;</span><span style="color: #DD0000">"failed&nbsp;to&nbsp;decrypt!"</span><span style="color: #007700">;<br />}<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
    </div>

   </div>
  </p>
 </div>


</div></div></div></body></html>